﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devtm.ServiceModel.Proxy;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace Devtm.ServiceModel.Resolver.Connectors
{
    internal class ConfigurationConnector : IServiceConnector
    {


        public ConfigurationConnector(IServiceResolver resolver, System.Configuration.Configuration configuration, string endpointConfigurationName, EndpointAddress remoteAddress, params IEndpointBehavior[] behaviors)
        {
            Resolver = resolver;
            Configuration = configuration;
            EndpointConfigurationName = endpointConfigurationName;
            Behaviors = behaviors;
            RemoteAddress = remoteAddress;

            if (string.IsNullOrEmpty(EndpointConfigurationName))
                endpointConfigurationName = "*";

        }


        public object[] Parameters() 
        {
            UsedCount++;
            return new object[] { Configuration, EndpointConfigurationName, RemoteAddress, Behaviors };
        }


        public IServiceResolver Resolver { get; private set; }
        public System.Configuration.Configuration Configuration { get; set; }
        public IEndpointBehavior[] Behaviors { get; set; }
        public string EndpointConfigurationName { get; set; }
        public EndpointAddress RemoteAddress { get; set; }
        public int UsedCount { get; private set; }



        public Uri Uri
        {
            get { return RemoteAddress.Uri; }
        }

        public Binding Binding
        {
            get { return null; }
        }
    }
}
